import axios from 'axios'
//post请求使用
export function request(config) {
	//创建axios的实例
	// console.log(config)
	const instance = axios.create({
		baseURL: 'http://127.0.0.1:8888/api/private/v1',
		timeout: 5000
	});
	//axios拦截器
	instance.interceptors.request.use(config => {
		// console.log(config);
		config.headers.Authorization = window.sessionStorage.getItem('token');
		return config
	}, err => {
		return err
	});

	instance.interceptors.response.use(response => {
		// console.log('来到了response拦截success中');
		return response.data
	}, err => {
		console.log('来到了response拦截failure中');
		console.log(err);
		if (err && err.response) {
			switch (err.response.status) {
				case 400:
					err.message = '请求错误'
					break
				case 401:
					err.message = '未授权的访问'
					break
			}
		}
		return err
	});
	//发送网络请求
	return instance(config)
}